<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return['ischecklogin']=cfc('core')->checklogin('','',true);
$credit_types=credit_types(true);
if($_RQ['op']=='get'){
	$member=$this->get('member',array('mid'=>$_SESSION['uid']));
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	$return['member']=$member;
	$data['service_money']=0;
	$data['cash_money']=0;
	$return['data']=$data;
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$wxapppay_types=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$wxapppay_types[]=array(
				'key'=>'credit',
				'title'=>$this->pay_types['credit'],
			);
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$wxapppay_types[]=array(
				'key'=>'wechat',
				'title'=>$this->pay_types['wechat'],
			);
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$wxapppay_types[]=array(
				'key'=>'alipay',
				'title'=>$this->pay_types['alipay'],
			);
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$wxapppay_types[]=array(
				'key'=>'union',
				'title'=>$this->pay_types['union'],
			);
			$pay_type=$pay_type?:'union';
		}
		$check=strstr($this->setting['withdrawtype'],'downline');
		if($check){
			$withdrawtype['downline']=$this->pay_types['downline'];
			$wxapppay_types[]=array(
				'key'=>'downline',
				'title'=>$this->pay_types['downline'],
			);
			$pay_type=$pay_type?:'downline';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$wxapppay_types=array();
	foreach($return['pay_types'] as $k=>$pv){
		$wxapppay_types[]=array(
			'key'=>$k,
			'title'=>$pv,
		);
	}
	$return['wxapppay_types']=$wxapppay_types;
	$check=strstr($this->setting['withdrawtype'],'alipay');
	if($check){
		$type_array[1]='提现到支付宝';
        $post1=$this->get('balance',array('pay_type'=>'alipay','mid'=>$_SESSION['uid']),array('alipay','realname'),'id desc');
	}
	$check=strstr($this->setting['withdrawtype'],'union');
	if($check){
		$type_array[2]='提现到银行卡';
        $post2=$this->get('balance',array('pay_type'=>'union','mid'=>$_SESSION['uid']),array('bankname','bankcard','realname'),'id desc');
        $post2['bankcard1']=$post2['bankcard'];
	}
    if($post1 || $post2) {
        $return['post'] = array_merge($post1, $post2);
    }
	$return['post']['pay_type']=$pay_type;
	$return['post']['fee']=0;
	$return['level']=pdo_get('jy_dayfee_level',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['level_id']));
	set_html('title','我的广告值');
	exi($return);
}
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'type'=>array(1,3,4,5,8,9,12,13,14));
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_dayfee_feelog',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['statustitle']=$this->feelog_status[$item['status']];
			$item['typetitle']=$this->feelog_types[$item['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='zlog'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid OR'=>"mid=".$_SESSION['uid']." or tomid=".$_SESSION['uid']);
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_dayfee_zlog',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['statustitle']=$this->feelog_status[$item['status']];
			$item['typetitle']=$this->zlog_types[$item['type']];
			if($item['mid']!=$_SESSION['uid']){
				$item['typetitle']='来自他人赠送';
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
//结算
if($_RQ['op']=='balance'){
	$post=get_postdata();
	$this->model('commission')->create_balance($_SESSION['uid'],$post,2);
	exi('提交成功！等待审核！','','get');
}
//兑换
if($_RQ['op']=='change'){
	$post=get_postdata();
	if(!$this->setting['is_tongprice']){
		exi('还未设置通证价格！无法兑换！','error');
	}
	$member=$this->get('member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$afee=$post['duinum']*$this->setting['is_tongprice'];
	if($member['a_sffee']<$afee){
		exi('广告值不足，无法兑换！','error');
	}
	$new_balance=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'znum'=>$post['duinum'],
			'zprice'=>$this->setting['is_tongprice'],
			'afee'=>$afee,
			'type'=>0,
			'createtime'=>TIMESTAMP,
			'status'=>1,
	);
	$this->insert('zlog',$new_balance);
	pdo_update('jy_dayfee_member',array('z_allnum +='=>$post['duinum'],'z_lastnum +='=>$post['duinum']),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$this->model('member')->member_feelog($_SESSION['uid'],'a_sffee',$afee,false,14);
	exi('兑换成功！','','get');
}
//通行证赠送
if($_RQ['op']=='zzhuan'){
	$post=get_postdata();
	if(!intval($post['znum'])){
		exi('请填写赠送通证数量！','error');
	}
	$member=$this->get('member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if($member['z_lastnum']<$post['znum']){
		exi('通行证不足，无法赠送！','error');
	}
	if(!$post['tomid']){
		exi('请填写赠送人MID！','error');
	}
	$tomember=$this->get('member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$post['tomid']));
	if(!$tomember['id']){
		exi('赠送人MID不存在！','error');
	}
	$new_balance=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'tomid'=>$post['tomid'],
			'znum'=>$post['znum'],
			'type'=>2,
			'createtime'=>TIMESTAMP,
			'status'=>0,
	);
	$this->insert('zlog',$new_balance);
	$this->model('member')->member_feelog($_SESSION['uid'],'z_lastnum',$post['znum'],false,16);
	pdo_update('jy_dayfee_member',array('z_allnum +='=>$post['znum'],'z_lastnum +='=>$post['znum']),array('mid'=>$post['tomid'],'uniacid'=>$_SESSION['uniacid']));
	exi('提交成功！','','get');
}
//通行证提现
if($_RQ['op']=='ztixian'){
	$post=get_postdata();
	$member=$this->get('member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if($member['z_lastnum']<1){
		exi('通行证不足，无法提现！','error');
	}
	$new_balance=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'ztitle'=>$post['ztitle'],
			'zname'=>$post['zname'],
			'znum'=>$member['z_lastnum'],
			'type'=>1,
			'createtime'=>TIMESTAMP,
			'status'=>0,
	);
	$this->insert('zlog',$new_balance);
	$this->model('member')->member_feelog($_SESSION['uid'],'z_lastnum',$member['z_lastnum'],false,15);
	exi('提交成功！','','get');
}